package src 
{
	import fl.motion.Keyframe;
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	/**
	 * ...
	 * @author Felipe Soares Pinhel
	 */
	public class Controller 
	{
		
		public var x : Number;
		public var y : Number;
		public var speedX : Number;
		public var speedY : Number;
		private var left  : Boolean;
		private var right : Boolean;
		
		public var space  : Boolean;
		
		public function Controller( _x : Number, _y : Number) 
		{
			trace("CONTROLLER");
			this.x = _x;
			this.y = _y;
			
			init();
			
		}
		
		private function init() : void
		{
			
			speedX = 3;
			speedY = 3;
			
			Main._instance.stage.addEventListener(
			KeyboardEvent.KEY_DOWN, onKeyPress, false, 0, true);
			
			Main._instance.stage.addEventListener(
			KeyboardEvent.KEY_UP, onKeyRelease, false, 0, true);
			
		}
		
		private function onKeyPress ( e : KeyboardEvent ) : void
		{
			trace("KEYBOARD");
			
			switch( e.keyCode )
			{
				case Keyboard.LEFT : 
					left = true;
					
				break;
				
				case Keyboard.RIGHT : 
					right = true;
					
				break;
				
				case Keyboard.SPACE : 
					space = true;
				break;
				
			}
			
		}
		
		private function onKeyRelease ( e : KeyboardEvent )  : void
		{
			switch( e.keyCode )
			{
				case Keyboard.LEFT : 
					left = false;
				break;
				
				case Keyboard.RIGHT : 
					right = false;
				break;
			}
			
		}
		
		public function update() : void
		{
			if ( left)
			{
				x -= speedX;
				
			}
			
			if ( right )
			{
				x += speedX;
				
			}
			
		}		
		
	}

}